package edu.etu.sob.resource;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import virtuoso.jena.driver.VirtGraph;

import com.hp.hpl.jena.graph.Triple;

import edu.etu.sob.model.Todo;
import edu.etu.sob.model.impl.NodeWrapper;
import edu.etu.sob.model.impl.RDFTripleDesc;
import edu.etu.sob.service.GraphManager;

@Path("/rdf/{uri}")
public class RDFTripleResource {
	
	private GraphManager graphManager;
	private String url = "http://www.co-ode.org/ontologies/pizza/pizza.owl";

	public RDFTripleResource() {
		graphManager = new GraphManager();
	}

	public Todo getTodos(@PathParam("uri") String uri) {
		Todo todo = new Todo();
		todo.setDescription(url+"#"+uri);
		todo.setSummary("sssss");
		return todo;
	}
	
	@GET
	@Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
	public RDFTripleDesc getTripleDesc(@PathParam("uri") String uri) throws IOException {
		VirtGraph graph = graphManager.createGraph("Pizza");

		String fullURI = url+"#"+uri;
		RDFTripleDesc tripleDesc = new RDFTripleDesc(uri, fullURI);
		List<Triple> sc = graphManager.readSuperClasses(fullURI, graph);
		List<NodeWrapper> nw = new ArrayList<NodeWrapper>(); 
		for (Triple element : sc) {
			nw.add(new NodeWrapper(element));
		}
		tripleDesc.setSuperClasses(nw);
		
		System.out.println("in getTripleDesc for : " + uri);
		
		return tripleDesc;
	}
}
